<?php

namespace addon\ly_shareholder\app\listener\order;

use addon\ly_shareholder\app\model\Shareholder;
use addon\ly_shareholder\app\service\core\CoreShareholderLevelService;
use think\facade\Log;
use app\model\member\Member;

class AfterShopOrderFinish
{
    public function handle($data){
       Log::write('==================AfterShopOrderFinish' . '===========股东分红=======', 'DEBUG');
       $oreder_data = $data['order_data'];
       $site_id = $oreder_data['site_id'];
       $member_id = $oreder_data['member_id'];

    //    $shareholder = (new Shareholder())->where('site_id', $site_id)->where('member_id', $member_id)->find();
       $member = (new Member())->where('site_id', $site_id)->where('member_id', $member_id)->find();
       Log::write('===============ly_shareholder会员是否是股东===============' . $member);
       
       // 直接调用统一的股东升级处理方法
       CoreShareholderLevelService::shareholderUpgrade($site_id, $member_id);
        
       // 如果会员有上级，也为上级检查升级
       if (!empty($member['pid'])) {
           CoreShareholderLevelService::shareholderUpgrade($site_id, $member['pid']);
       }

    }



}
